package com.qf.om.entity;

import lombok.Data;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Data
public class Admin implements Serializable {
    static final long serialVersionUID = 123L;

    private String username;
    private String password;
    private String name;
    private String sex;
    private Date birthday;
    private List<String> powers;
    private String hometown;
    private String header;

        //    日期格式转换
    public void setBirthday(String birthday){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        try {
            this.birthday =sdf.parse((birthday));
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    public List<String> getPowers() {
        return powers;
    }

    public void setPowers(List<String> powers) {
        this.powers = powers;
    }

    public synchronized void addPower(String power){
        if (this.powers==null){
//            初始化变成集合
            this.powers=new ArrayList<>();
        }
        this.powers.add(power);
    }

    //数组转化成集合
        public void setPowers(String[] powers){
            this.powers = Arrays.asList(powers);
        }

}
